<?php

namespace App\Containers\AppSection\BankDetail\UI\API\Requests;

use App\Containers\AppSection\Ban\Traits\ProfilesBan;
use App\Containers\AppSection\Ban\Traits\UsersBan;
use App\Containers\AppSection\BankDetail\Tasks\FindBankDetailByIdTask;
use App\Containers\AppSection\BankDetail\Traits\IsOwnerProfileTrait;
use App\Ship\Parents\Requests\Request;
use App\Ship\Traits\AccreditationStatusPermissionTrait;

class DeleteBankDetailRequest extends Request
{
    use AccreditationStatusPermissionTrait;
    use IsOwnerProfileTrait;
    use ProfilesBan;
    use UsersBan;

    /**
     * Define which Roles and/or Permissions has access to this request.
     */
    protected array $access = [
        'permissions' => '',
        'roles' => 'borrower',
    ];

    /**
     * Id's that needs decoding before applying the validation rules.
     */
    protected array $decode = [
        // 'id',
    ];

    /**
     * Defining the URL parameters (e.g, `/user/{id}`) allows applying
     * validation rules on them and allows accessing them like request data.
     */
    protected array $urlParameters = [
        // 'id',
    ];

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [];
    }

    public function isMasterAccount(): bool
    {
        $bankDetail = app(FindBankDetailByIdTask::class)->run($this->id);
        return $bankDetail->master_account != true;
    }

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->check([
            'hasAccess',
            'profileIsNotRejected',
            'isOwnerProfile',
            'isMasterAccount',
            'profileIsNotBanned',
            'userIsNotBanned'
        ]);
    }
}
